package com.jiang.myfm.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiang.myfm.R;
import com.jiang.myfm.entities.anchor.AnchorEntity;
import com.squareup.picasso.Picasso;

/**
 * Created by Administrator on 2016/12/6.
 */
public class AnchorAdapter extends RecyclerView.Adapter<AnchorAdapter.ViewHolder>{

    private AnchorEntity mAnchorEntity;
    private Context context;


    public AnchorAdapter(AnchorEntity anchorEntity, Context context) {
        mAnchorEntity = anchorEntity;
        this.context = context;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=LayoutInflater.from(context).inflate(R.layout.layout_findfragment_5,parent,false);
        ViewHolder holder=new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.hot_tv.setText(mAnchorEntity.getList().get(position).getTitle());
        holder.hot_text_1.setText(mAnchorEntity.getList().get(position).getList().get(0).getNickname());
        holder.hot_text_2.setText(mAnchorEntity.getList().get(position).getList().get(1).getNickname());
        holder.hot_text_3.setText(mAnchorEntity.getList().get(position).getList().get(2).getNickname());
//        Log.d("flag",mAnchorEntity.getList().get(position).getList().get(0).getNickname());
        Picasso.with(context).load(mAnchorEntity.getList().get(position).getList().get(0).getSmallLogo()).into(holder.hot_image_1);
        Picasso.with(context).load(mAnchorEntity.getList().get(position).getList().get(1).getSmallLogo()).into(holder.hot_image_2);
        Picasso.with(context).load(mAnchorEntity.getList().get(position).getList().get(2).getSmallLogo()).into(holder.hot_image_3);



    }

    @Override
    public int getItemCount() {
        if (mAnchorEntity==null){
//            Log.d("getCount","====000===");
            return 0;
        }else {
            return mAnchorEntity.getList().size();
        }
//Log.e("getCount",""+mAnchorEntity.getList().size());
//        return mAnchorEntity.getList().size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView hot_image_1,hot_image_2,hot_image_3;
        TextView hot_text_1,hot_text_2,hot_text_3,hot_tv;

        public ViewHolder(View itemView) {
            super(itemView);
            hot_image_1= (ImageView) itemView.findViewById(R.id.hot_image_1);
            hot_image_2= (ImageView) itemView.findViewById(R.id.hot_image_2);
            hot_image_3= (ImageView) itemView.findViewById(R.id.hot_image_3);
            hot_text_1= (TextView) itemView.findViewById(R.id.hot_text_1);
            hot_text_2= (TextView) itemView.findViewById(R.id.hot_text_2);
            hot_text_3= (TextView) itemView.findViewById(R.id.hot_text_3);
            hot_tv= (TextView) itemView.findViewById(R.id.hot_tv);
        }
    }
    public void addAll(AnchorEntity anchorEntity){
        mAnchorEntity = anchorEntity;
//        Log.d("flag",mAnchorEntity.getList().get(0).getList().get(0).getNickname());
        notifyDataSetChanged();
    }
}
